import { type SiteGroup } from '@/api/SiteGroupApi.ts'
import { ArrayTool } from '@es-tool/core'
import { defineStore } from 'pinia'
import { ref } from 'vue'


export const useSiteGroupStore = defineStore('站点分组', () => {
    const groupIsLoading = ref(false)
    const groupList = ref<Array<SiteGroup>>([])
    const currentGroup = ref<string>('')

    const switchGroup = (group: SiteGroup) => currentGroup.value = group.id!

    const selectFirst = () => {
        if (!currentGroup.value && ArrayTool.isNotEmpty(groupList.value)) {
            currentGroup.value = groupList.value[0].id!
        }
    }

    return {
        groupIsLoading,
        groupList,
        currentGroup,
        selectFirst,
        switchGroup,
    }
})
